#!/usr/bin/env python
#coding=utf-8

import urllib, datetime
from BeautifulSoup import BeautifulSoup 
import bsddb, logging

def get_coder(db="/home/jay/codes.db"):
    b = bsddb.btopen(db, 'r')
    return b

def get_logger(f='/home/jay/stock.log'):
    
    logger = logging.getLogger()
    h = logging.FileHandler(f)
    formatter = logging.Formatter('%(asctime)s \t %(levelname)s \t %(message)s')
    h.setFormatter(formatter)
    logger.addHandler(h)
    logger.setLevel(logging.NOTSET)
    
    return logger

def get_db_connector(db="/home/jay/stocks"):pass
    
def get_coder(db="/home/jay/codes.db"):
    b = bsddb.btopen(db, 'r')
    return b

def get_date_isostr(y,m,d):
    return datetime.date(y,m,d).isoformat()
def get_today_isostr(y,m,d):
    return datetime.date.today().isoformat()
def get_sohu_datestr(y,m,d):
    isostr = get_date_isostr(y,m,d)
    return ''.join(isostr.split('-'))

def get_soup(url):
    f = urllib.urlopen(url)
    soup = BeautifulSoup(f, fromEncoding='gb18030') 
    return soup
